from django.test import LiveServerTestCase
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

class MalachiteAppTest(LiveServerTestCase):
    fixtures = ['user.json']

    def setUp(self):
        self.browser = webdriver.Firefox()

    def tearDown(self):
        self.browser.quit()

    def test__can_login_as_admin(self):
        self.browser.get(self.live_server_url + "/admin/")
        login_form = self.browser.find_element_by_id('login-form')

        # Test that we got a login form first
        self.assertEquals(login_form.tag_name, 'form')

        # Now log in
        username_field = self.browser.find_element_by_name('username')
        password_field = self.browser.find_element_by_name('password')
        username_field.send_keys('admin')
        password_field.send_keys('admin')
        password_field.send_keys(Keys.RETURN)

        # Check if it looks like an admin section
        #user_tools = self.browser.find_element_by_id('user-tools')
        #self.assertTrue(user_tools)

        # Check that Malachite is installed
        body = self.browser.find_element_by_tag_name('body')
        self.assertTrue('Malachite' in body.text)
        self.assertTrue('Posts' in body.text)
        self.assertTrue('Tags' in body.text)

        # Check that Posts and Tags are registered
        #post_link = self.browser

